<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/random/uniform_01.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/random</a> - uniform_01.hpp<span style="font-size: 80%;"> (source / <a href="uniform_01.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntryHi">-</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /* boost random/uniform_01.hpp header file</a>
<span class="lineNum">       2 </span>            :  *
<span class="lineNum">       3 </span>            :  * Copyright Jens Maurer 2000-2001
<span class="lineNum">       4 </span>            :  * Distributed under the Boost Software License, Version 1.0. (See
<span class="lineNum">       5 </span>            :  * accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       6 </span>            :  * http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       7 </span>            :  *
<span class="lineNum">       8 </span>            :  * See http://www.boost.org for most recent version including documentation.
<span class="lineNum">       9 </span>            :  *
<span class="lineNum">      10 </span>            :  * $Id$
<span class="lineNum">      11 </span>            :  *
<span class="lineNum">      12 </span>            :  * Revision history
<span class="lineNum">      13 </span>            :  *  2001-02-18  moved to individual header files
<span class="lineNum">      14 </span>            :  */
<span class="lineNum">      15 </span>            : 
<span class="lineNum">      16 </span>            : #ifndef BOOST_RANDOM_UNIFORM_01_HPP
<span class="lineNum">      17 </span>            : #define BOOST_RANDOM_UNIFORM_01_HPP
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : #include &lt;iostream&gt;
<span class="lineNum">      20 </span>            : #include &lt;boost/config.hpp&gt;
<span class="lineNum">      21 </span>            : #include &lt;boost/limits.hpp&gt;
<span class="lineNum">      22 </span>            : #include &lt;boost/static_assert.hpp&gt;
<span class="lineNum">      23 </span>            : #include &lt;boost/random/detail/config.hpp&gt;
<span class="lineNum">      24 </span>            : #include &lt;boost/random/detail/ptr_helper.hpp&gt;
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            : #include &lt;boost/random/detail/disable_warnings.hpp&gt;
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            : namespace boost {
<span class="lineNum">      29 </span>            : namespace random {
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            : #ifdef BOOST_RANDOM_DOXYGEN
<span class="lineNum">      32 </span>            : 
<span class="lineNum">      33 </span>            : /**
<span class="lineNum">      34 </span>            :  * The distribution function uniform_01 models a \random_distribution.
<span class="lineNum">      35 </span>            :  * On each invocation, it returns a random floating-point value
<span class="lineNum">      36 </span>            :  * uniformly distributed in the range [0..1).
<span class="lineNum">      37 </span>            :  *
<span class="lineNum">      38 </span>            :  * The template parameter RealType shall denote a float-like value type
<span class="lineNum">      39 </span>            :  * with support for binary operators +, -, and /.
<span class="lineNum">      40 </span>            :  *
<span class="lineNum">      41 </span>            :  * Note: The current implementation is buggy, because it may not fill
<span class="lineNum">      42 </span>            :  * all of the mantissa with random bits. I'm unsure how to fill a
<span class="lineNum">      43 </span>            :  * (to-be-invented) @c boost::bigfloat class with random bits efficiently.
<span class="lineNum">      44 </span>            :  * It's probably time for a traits class.
<span class="lineNum">      45 </span>            :  */
<span class="lineNum">      46 </span>            : template&lt;class RealType = double&gt;
<span class="lineNum">      47 </span>            : class uniform_01
<span class="lineNum">      48 </span>            : {
<span class="lineNum">      49 </span>            : public:
<span class="lineNum">      50 </span>            :   typedef RealType input_type;
<span class="lineNum">      51 </span>            :   typedef RealType result_type;
<span class="lineNum">      52 </span>            :   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const;
<span class="lineNum">      53 </span>            :   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const;
<span class="lineNum">      54 </span>            :   void reset();
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span>            :   template&lt;class Engine&gt;
<span class="lineNum">      57 </span>            :   result_type operator()(Engine&amp; eng);
<span class="lineNum">      58 </span>            : 
<span class="lineNum">      59 </span>            : #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
<span class="lineNum">      60 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">      61 </span>            :   friend std::basic_ostream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">      62 </span>            :   operator&lt;&lt;(std::basic_ostream&lt;CharT,Traits&gt;&amp; os, const new_uniform_01&amp;)
<span class="lineNum">      63 </span>            :   {
<span class="lineNum">      64 </span>            :     return os;
<span class="lineNum">      65 </span>            :   }
<span class="lineNum">      66 </span>            : 
<span class="lineNum">      67 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">      68 </span>            :   friend std::basic_istream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">      69 </span>            :   operator&gt;&gt;(std::basic_istream&lt;CharT,Traits&gt;&amp; is, new_uniform_01&amp;)
<span class="lineNum">      70 </span>            :   {
<span class="lineNum">      71 </span>            :     return is;
<span class="lineNum">      72 </span>            :   }
<span class="lineNum">      73 </span>            : #endif
<span class="lineNum">      74 </span>            : };
<span class="lineNum">      75 </span>            : 
<span class="lineNum">      76 </span>            : #else
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            : namespace detail {
<span class="lineNum">      79 </span>            : 
<span class="lineNum">      80 </span>            : template&lt;class RealType&gt;
<span class="lineNum">      81 </span>            : class new_uniform_01
<span class="lineNum">      82 </span>            : {
<span class="lineNum">      83 </span>            : public:
<span class="lineNum">      84 </span>            :   typedef RealType input_type;
<span class="lineNum">      85 </span>            :   typedef RealType result_type;
<span class="lineNum">      86 </span>            :   // compiler-generated copy ctor and copy assignment are fine
<span class="lineNum">      87 </span>            :   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
<span class="lineNum">      88 </span>            :   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
<span class="lineNum">      89 </span>            :   void reset() { }
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span>            :   template&lt;class Engine&gt;
<span class="lineNum">      92 </span>            :   result_type operator()(Engine&amp; eng) {
<span class="lineNum">      93 </span>            :     for (;;) {
<span class="lineNum">      94 </span>            :       typedef typename Engine::result_type base_result;
<span class="lineNum">      95 </span>            :       result_type factor = result_type(1) /
<span class="lineNum">      96 </span>            :               (result_type((eng.max)()-(eng.min)()) +
<span class="lineNum">      97 </span>            :                result_type(std::numeric_limits&lt;base_result&gt;::is_integer ? 1 : 0));
<span class="lineNum">      98 </span><span class="lineNoCov">          0 :       result_type result = result_type(eng() - (eng.min)()) * factor;</span>
<span class="lineNum">      99 </span><span class="lineNoCov">          0 :       if (result &lt; result_type(1))</span>
<span class="lineNum">     100 </span>            :         return result;
<span class="lineNum">     101 </span>            :     }
<span class="lineNum">     102 </span>            :   }
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span>            : #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
<span class="lineNum">     105 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">     106 </span>            :   friend std::basic_ostream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     107 </span>            :   operator&lt;&lt;(std::basic_ostream&lt;CharT,Traits&gt;&amp; os, const new_uniform_01&amp;)
<span class="lineNum">     108 </span>            :   {
<span class="lineNum">     109 </span>            :     return os;
<span class="lineNum">     110 </span>            :   }
<span class="lineNum">     111 </span>            : 
<span class="lineNum">     112 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">     113 </span>            :   friend std::basic_istream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     114 </span>            :   operator&gt;&gt;(std::basic_istream&lt;CharT,Traits&gt;&amp; is, new_uniform_01&amp;)
<span class="lineNum">     115 </span>            :   {
<span class="lineNum">     116 </span>            :     return is;
<span class="lineNum">     117 </span>            :   }
<span class="lineNum">     118 </span>            : #endif
<span class="lineNum">     119 </span>            : };
<span class="lineNum">     120 </span>            : 
<span class="lineNum">     121 </span>            : template&lt;class UniformRandomNumberGenerator, class RealType&gt;
<span class="lineNum">     122 </span>            : class backward_compatible_uniform_01
<span class="lineNum">     123 </span>            : {
<span class="lineNum">     124 </span>            :   typedef boost::random::detail::ptr_helper&lt;UniformRandomNumberGenerator&gt; traits;
<span class="lineNum">     125 </span>            : public:
<span class="lineNum">     126 </span>            :   typedef UniformRandomNumberGenerator base_type;
<span class="lineNum">     127 </span>            :   typedef RealType result_type;
<span class="lineNum">     128 </span>            : 
<span class="lineNum">     129 </span>            :   BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
<span class="lineNum">     130 </span>            : 
<span class="lineNum">     131 </span>            : #if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS)
<span class="lineNum">     132 </span>            :   BOOST_STATIC_ASSERT(!std::numeric_limits&lt;RealType&gt;::is_integer);
<span class="lineNum">     133 </span>            : #endif
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span>            :   explicit backward_compatible_uniform_01(typename traits::rvalue_type rng)
<span class="lineNum">     136 </span>            :     : _rng(rng),
<span class="lineNum">     137 </span>            :       _factor(result_type(1) /
<span class="lineNum">     138 </span>            :               (result_type((base().max)()-(base().min)()) +
<span class="lineNum">     139 </span>            :                result_type(std::numeric_limits&lt;base_result&gt;::is_integer ? 1 : 0)))
<span class="lineNum">     140 </span>            :   {
<span class="lineNum">     141 </span>            :   }
<span class="lineNum">     142 </span>            :   // compiler-generated copy ctor and copy assignment are fine
<span class="lineNum">     143 </span>            : 
<span class="lineNum">     144 </span>            :   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
<span class="lineNum">     145 </span>            :   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
<span class="lineNum">     146 </span>            :   typename traits::value_type&amp; base() { return traits::ref(_rng); }
<span class="lineNum">     147 </span>            :   const typename traits::value_type&amp; base() const { return traits::ref(_rng); }
<span class="lineNum">     148 </span>            :   void reset() { }
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            :   result_type operator()() {
<span class="lineNum">     151 </span>            :     for (;;) {
<span class="lineNum">     152 </span>            :       result_type result = result_type(base()() - (base().min)()) * _factor;
<span class="lineNum">     153 </span>            :       if (result &lt; result_type(1))
<span class="lineNum">     154 </span>            :         return result;
<span class="lineNum">     155 </span>            :     }
<span class="lineNum">     156 </span>            :   }
<span class="lineNum">     157 </span>            : 
<span class="lineNum">     158 </span>            : #if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) &amp;&amp; !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
<span class="lineNum">     159 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">     160 </span>            :   friend std::basic_ostream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     161 </span>            :   operator&lt;&lt;(std::basic_ostream&lt;CharT,Traits&gt;&amp; os, const backward_compatible_uniform_01&amp; u)
<span class="lineNum">     162 </span>            :   {
<span class="lineNum">     163 </span>            :     os &lt;&lt; u._rng;
<span class="lineNum">     164 </span>            :     return os;
<span class="lineNum">     165 </span>            :   }
<span class="lineNum">     166 </span>            : 
<span class="lineNum">     167 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">     168 </span>            :   friend std::basic_istream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     169 </span>            :   operator&gt;&gt;(std::basic_istream&lt;CharT,Traits&gt;&amp; is, backward_compatible_uniform_01&amp; u)
<span class="lineNum">     170 </span>            :   {
<span class="lineNum">     171 </span>            :     is &gt;&gt; u._rng;
<span class="lineNum">     172 </span>            :     return is;
<span class="lineNum">     173 </span>            :   }
<span class="lineNum">     174 </span>            : #endif
<span class="lineNum">     175 </span>            : 
<span class="lineNum">     176 </span>            : private:
<span class="lineNum">     177 </span>            :   typedef typename traits::value_type::result_type base_result;
<span class="lineNum">     178 </span>            :   UniformRandomNumberGenerator _rng;
<span class="lineNum">     179 </span>            :   result_type _factor;
<span class="lineNum">     180 </span>            : };
<span class="lineNum">     181 </span>            : 
<span class="lineNum">     182 </span>            : #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
<span class="lineNum">     183 </span>            : //  A definition is required even for integral static constants
<span class="lineNum">     184 </span>            : template&lt;class UniformRandomNumberGenerator, class RealType&gt;
<span class="lineNum">     185 </span>            : const bool backward_compatible_uniform_01&lt;UniformRandomNumberGenerator, RealType&gt;::has_fixed_range;
<span class="lineNum">     186 </span>            : #endif
<span class="lineNum">     187 </span>            : 
<span class="lineNum">     188 </span>            : template&lt;class UniformRandomNumberGenerator&gt;
<span class="lineNum">     189 </span>            : struct select_uniform_01
<span class="lineNum">     190 </span>            : {
<span class="lineNum">     191 </span>            :   template&lt;class RealType&gt;
<span class="lineNum">     192 </span>            :   struct apply
<span class="lineNum">     193 </span>            :   {
<span class="lineNum">     194 </span>            :     typedef backward_compatible_uniform_01&lt;UniformRandomNumberGenerator, RealType&gt; type;
<span class="lineNum">     195 </span>            :   };
<span class="lineNum">     196 </span>            : };
<span class="lineNum">     197 </span>            : 
<span class="lineNum">     198 </span>            : template&lt;&gt;
<span class="lineNum">     199 </span>            : struct select_uniform_01&lt;float&gt;
<span class="lineNum">     200 </span>            : {
<span class="lineNum">     201 </span>            :   template&lt;class RealType&gt;
<span class="lineNum">     202 </span>            :   struct apply
<span class="lineNum">     203 </span>            :   {
<span class="lineNum">     204 </span>            :     typedef new_uniform_01&lt;float&gt; type;
<span class="lineNum">     205 </span>            :   };
<span class="lineNum">     206 </span>            : };
<span class="lineNum">     207 </span>            : 
<span class="lineNum">     208 </span>            : template&lt;&gt;
<span class="lineNum">     209 </span>            : struct select_uniform_01&lt;double&gt;
<span class="lineNum">     210 </span>            : {
<span class="lineNum">     211 </span>            :   template&lt;class RealType&gt;
<span class="lineNum">     212 </span>            :   struct apply
<span class="lineNum">     213 </span>            :   {
<span class="lineNum">     214 </span>            :     typedef new_uniform_01&lt;double&gt; type;
<span class="lineNum">     215 </span>            :   };
<span class="lineNum">     216 </span>            : };
<span class="lineNum">     217 </span>            : 
<span class="lineNum">     218 </span>            : template&lt;&gt;
<span class="lineNum">     219 </span>            : struct select_uniform_01&lt;long double&gt;
<span class="lineNum">     220 </span>            : {
<span class="lineNum">     221 </span>            :   template&lt;class RealType&gt;
<span class="lineNum">     222 </span>            :   struct apply
<span class="lineNum">     223 </span>            :   {
<span class="lineNum">     224 </span>            :     typedef new_uniform_01&lt;long double&gt; type;
<span class="lineNum">     225 </span>            :   };
<span class="lineNum">     226 </span>            : };
<span class="lineNum">     227 </span>            : 
<span class="lineNum">     228 </span>            : }
<span class="lineNum">     229 </span>            : 
<span class="lineNum">     230 </span>            : // Because it is so commonly used: uniform distribution on the real [0..1)
<span class="lineNum">     231 </span>            : // range.  This allows for specializations to avoid a costly int -&gt; float
<span class="lineNum">     232 </span>            : // conversion plus float multiplication
<span class="lineNum">     233 </span>            : template&lt;class UniformRandomNumberGenerator = double, class RealType = double&gt;
<span class="lineNum">     234 </span>            : class uniform_01
<span class="lineNum">     235 </span>            :   : public detail::select_uniform_01&lt;UniformRandomNumberGenerator&gt;::BOOST_NESTED_TEMPLATE apply&lt;RealType&gt;::type
<span class="lineNum">     236 </span>            : {
<span class="lineNum">     237 </span>            :   typedef typename detail::select_uniform_01&lt;UniformRandomNumberGenerator&gt;::BOOST_NESTED_TEMPLATE apply&lt;RealType&gt;::type impl_type;
<span class="lineNum">     238 </span>            :   typedef boost::random::detail::ptr_helper&lt;UniformRandomNumberGenerator&gt; traits;
<span class="lineNum">     239 </span>            : public:
<span class="lineNum">     240 </span>            : 
<span class="lineNum">     241 </span>            :   uniform_01() {}
<span class="lineNum">     242 </span>            : 
<span class="lineNum">     243 </span>            :   explicit uniform_01(typename traits::rvalue_type rng)
<span class="lineNum">     244 </span>            :     : impl_type(rng)
<span class="lineNum">     245 </span>            :   {
<span class="lineNum">     246 </span>            :   }
<span class="lineNum">     247 </span>            : 
<span class="lineNum">     248 </span>            : #if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) &amp;&amp; !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
<span class="lineNum">     249 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">     250 </span>            :   friend std::basic_ostream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     251 </span>            :   operator&lt;&lt;(std::basic_ostream&lt;CharT,Traits&gt;&amp; os, const uniform_01&amp; u)
<span class="lineNum">     252 </span>            :   {
<span class="lineNum">     253 </span>            :     os &lt;&lt; static_cast&lt;const impl_type&amp;&gt;(u);
<span class="lineNum">     254 </span>            :     return os;
<span class="lineNum">     255 </span>            :   }
<span class="lineNum">     256 </span>            : 
<span class="lineNum">     257 </span>            :   template&lt;class CharT, class Traits&gt;
<span class="lineNum">     258 </span>            :   friend std::basic_istream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     259 </span>            :   operator&gt;&gt;(std::basic_istream&lt;CharT,Traits&gt;&amp; is, uniform_01&amp; u)
<span class="lineNum">     260 </span>            :   {
<span class="lineNum">     261 </span>            :     is &gt;&gt; static_cast&lt;impl_type&amp;&gt;(u);
<span class="lineNum">     262 </span>            :     return is;
<span class="lineNum">     263 </span>            :   }
<span class="lineNum">     264 </span>            : #endif
<span class="lineNum">     265 </span>            : };
<span class="lineNum">     266 </span>            : 
<span class="lineNum">     267 </span>            : #endif
<span class="lineNum">     268 </span>            : 
<span class="lineNum">     269 </span>            : } // namespace random
<span class="lineNum">     270 </span>            : 
<span class="lineNum">     271 </span>            : using random::uniform_01;
<span class="lineNum">     272 </span>            : 
<span class="lineNum">     273 </span>            : } // namespace boost
<span class="lineNum">     274 </span>            : 
<span class="lineNum">     275 </span>            : #include &lt;boost/random/detail/enable_warnings.hpp&gt;
<span class="lineNum">     276 </span>            : 
<span class="lineNum">     277 </span>            : #endif // BOOST_RANDOM_UNIFORM_01_HPP
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
